#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查条文数据字段
"""

import sys
import os
sys.path.append('backend')

from backend.app import create_app
from backend.app.services.civil_code_service import civil_code_service

def check_fields():
    """检查条文字段"""
    print("检查条文数据字段")
    
    app = create_app()
    
    with app.app_context():
        try:
            civil_code_service._init_db()
            
            if civil_code_service.collection is None:
                print("collection为None")
                return
            
            # 查看一个条文的所有字段
            article = civil_code_service.collection.find_one({"article_number": "第一千零七十条"})
            
            if article:
                print(f"条文字段: {list(article.keys())}")
                print(f"\narticle_number: {article.get('article_number')}")
                print(f"part: {article.get('part')}")
                print(f"chapter: {article.get('chapter')}")
                print(f"chapter_number: {article.get('chapter_number')}")
                print(f"chapter_title: {article.get('chapter_title')}")
                print(f"chapter_info: {article.get('chapter_info')}")
            else:
                print("未找到条文")
                
        except Exception as e:
            print(f"检查失败: {e}")
            import traceback
            traceback.print_exc()

if __name__ == "__main__":
    check_fields()
